<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,Chrome=1" />
  <title>Document</title>
</head>

<body>
  <div onclick="tester1()">switcher</div>
  <div onclick="tester2()">fnTable</div>
  <script>
    function tester1() {
      for (v = 0; v < 10; v++) {
        console.time("switcher");
        for (i = 0; i < 1000; i++) switcher("hhh");
        console.timeEnd("switcher");
      }
    }

    function tester2() {
      for (v = 0; v < 10; v++) {
        console.time("fnTable");
        for (i = 0; i < 1000; i++) fnTable("hhh");
        console.timeEnd("fnTable");
      }
    }

    var dataList = {
      qqq: function () {
        console.log(1);
      },
      www: function () {
        console.log(2);
      },
      eee: function () {
        console.log(3);
      },
      rrr: function () {
        console.log(4);
      },
      ttt: function () {
        console.log(5);
      },
      yyy: function () {
        console.log(6);
      },
      uuu: function () {
        console.log(7);
      },
      iii: function () {
        console.log(8);
      },
      ooo: function () {
        console.log(11);
      },
      ppp: function () {
        console.log(12);
      },
      aaa: function () {
        console.log(13);
      },
      sss: function () {
        console.log(14);
      },
      ddd: function () {
        console.log(15);
      },
      fff: function () {
        console.log(16);
      },
      ggg: function () {
        console.log(17);
      },
      hhh: function () {
        console.log(18);
      }
    }

    var aaa = {
      qqq: function () {
        console.log(1);
      },
      www: function () {
        console.log(2);
      },
      eee: function () {
        console.log(3);
      },
      rrr: function () {
        console.log(4);
      },
      ttt: function () {
        console.log(5);
      },
      yyy: function () {
        console.log(6);
      },
      uuu: function () {
        console.log(7);
      },
      iii: function () {
        console.log(8);
      },
      ooo: function () {
        console.log(11);
      },
      ppp: function () {
        console.log(12);
      },
      aaa: function () {
        console.log(13);
      },
      sss: function () {
        console.log(14);
      },
      ddd: function () {
        console.log(15);
      },
      fff: function () {
        console.log(16);
      },
      ggg: function () {
        console.log(17);
      },
      hhh: function () {
        console.log(18);
      }
    }

    function fnTable(ids) {
      // 检测 ? 有执行 : 无
      aaa[ids] ? aaa[ids]() : aaa["def"]();
    }

    function switcher(i) {
      switch (i) {
        case "qqq":
          console.log(1);
          break;
        case "www":
          console.log(2);
          break;
        case "eee":
          console.log(3);
          break;
        case "rrr":
          console.log(4);
          break;
        case "ttt":
          console.log(5);
          break;
        case "yyy":
          console.log(6);
          break;
        case "uuu":
          console.log(7);
          break;
        case "iii":
          console.log(8);
          break;
        case "ooo":
          console.log(11);
          break;
        case "ppp":
          console.log(12);
          break;
        case "aaa":
          console.log(13);
          break;
        case "sss":
          console.log(14);
          break;
        case "ddd":
          console.log(15);
          break;
        case "fff":
          console.log(16);
          break;
        case "ggg":
          console.log(17);
          break;
        case "hhh":
          console.log(18);
          break;
        default:
          break;
      }
    }

    // (function (fn) {
    //   let arr = {
    //     fn1: function () {
    //       console.log("fn1")
    //     },
    //     fn2: function () {
    //       console.log("fn2")
    //     },
    //     def: function () {
    //       console.log("def");
    //     }
    //   }
    //   arr[fn] ? arr[fn]() : arr["def"]();
    // }("fn1"))
  </script>
</body>

</html>